package com.example.administrator.popwindowdemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;

import com.example.administrator.popwindowdemo.view.CustomPopwindow;

public class MainActivity extends AppCompatActivity {
    private CustomPopwindow customPopwindow;
    private Activity mActivity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mActivity = this;
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                customPopwindow = new CustomPopwindow(mActivity,itemsOnClick);
                customPopwindow.showAtLocation(view,
                        Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });
    }
    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener(){

        public void onClick(View v) {
            customPopwindow.dismiss();
            customPopwindow.backgroundAlpha(mActivity,1f);
            switch (v.getId()) {
                case R.id.ll_select01:
                    //do something
                    break;
                case R.id.ll_select02:
                     //do something

                    break;
                default:
                    break;
            }
        }

    };

}
